#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;

void perm1(int* arr,int begin,int end) {
	if (begin == end) {
		for (int i = 0; i < end; ++i) printf("%d", arr[i]);
		printf("\n");
	}
	else 
		for (int i = begin; i < end; ++i)
		{
			swap(arr[i], arr[begin]);
			perm1(arr, begin + 1, end);
			swap(arr[i], arr[begin]);
		}
}
int main() {
	int n = 0;
	printf("input:");
	scanf("%d", &n);
	int* nums = (int*)malloc(sizeof(int) * n);
	for (int i = 0; i < n; ++i) nums[i] = i + 1;
	perm1(nums, 0, n);
	return 0;
}